package cn.itcast.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.itcast.pojo.User;

@Controller
@RequestMapping("hello2")
@RestController
// 该注解的作用：可以将类中的所有的方法的返回值响应为json数据
public class Hello2Controller {

	@RequestMapping("demo")
	public List<User> demo(Model model) {
		List<User> list = new ArrayList<User>();

		for (int i = 0; i < 20; i++) {
			User user = new User();
			user.setId(i + 1l);
			user.setUserName("admin" + i);
			user.setName("用户" + i);
			user.setAge(18 + i);
			list.add(user);
		}
		model.addAttribute("users", list);
		return list;

	}
	
	@RequestMapping("demo2")
	public String demo2(Model model){
		model.addAttribute("msg", "这是一个测试");
		return "hello";
	}

}
